package com.lbn.monitor.util;

import android.content.Context;
import android.util.Log;

import com.free.framework.lib.utils.PrefsMgr;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lbn.monitor.api.model.DataCnItem;
import com.lbn.monitor.api.model.Pollutant;
import com.lbn.monitor.api.model.RealTimeValue;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 李炳南
 * @date 2017/3/15
 */
public class DataUtils {


    private static List<Pollutant> data;

    public static List<Pollutant> getPollutants(Context context) {

        if (data == null) {
            synchronized (DataUtils.class) {
                if (data == null) {
                    String pollutantJson = (String) PrefsMgr.get(context, Constant.POLLUTANTS, "");
                    Type mType = new TypeToken<List<Pollutant>>() {
                    }.getType();
                    data = new Gson().fromJson(pollutantJson, mType);
                    if (data == null) {
                        data = new ArrayList<>();
                    }
                }
            }
        }
        return data;
    }


    public static List<DataCnItem> getTimeType() {
        List<DataCnItem> data = new ArrayList<>();
//        data.add(new DataCnItem("实时数据", "2011"));
        data.add(new DataCnItem("分钟数据", "2051"));
        data.add(new DataCnItem("小时数据", "2061"));
        data.add(new DataCnItem("日数据", "2031"));
        return data;
    }


    public static String getRtd(int id, RealTimeValue data) {
        String rtd = null;
        switch (id) {
            case 1:
                rtd = data.getStr01_Rtd();
                break;
            case 2:
                rtd = data.getStr02_Rtd();
                break;
            case 3:
                rtd = data.getStr03_Rtd();
                break;
            case 4:
                rtd = data.getStr04_Rtd();
                break;
            case 5:
                rtd = data.getStr05_Rtd();
                break;
            case 6:
                rtd = data.getStr06_Rtd();
                break;
            case 7:
                rtd = data.getStr07_Rtd();
                break;
            case 8:
                rtd = data.getStr08_Rtd();
                break;
            case 9:
                rtd = data.getStr09_Rtd();
                break;
            case 10:
                rtd = data.getStr10_Rtd();
                break;
            case 11:
                rtd = data.getS01_Rtd();
                break;
            case 12:
                rtd = data.getS02_Rtd();
                break;
            case 13:
                rtd = data.getS03_Rtd();
                break;
            case 14:
                rtd = data.getS04_Rtd();
                break;
            case 15:
                rtd = data.getS05_Rtd();
                break;
            case 16:
                rtd = data.getS06_Rtd();
                break;
            case 17:
                rtd = data.getS07_Rtd();
                break;
            case 18:
                rtd = data.getS08_Rtd();
                break;
            case 19:
                rtd = data.getB02_Rtd();
                break;
        }
        return rtd;
    }


    public static String getAvg(int id, RealTimeValue data) {
        String avg = null;
        switch (id) {
            case 1:
                avg = data.getStr01_Avg();
                break;
            case 2:
                avg = data.getStr02_Avg();
                break;
            case 3:
                avg = data.getStr03_Avg();
                break;
            case 4:
                avg = data.getStr04_Avg();
                break;
            case 5:
                avg = data.getStr05_Avg();
                break;
            case 6:
                avg = data.getStr06_Avg();
                break;
            case 7:
                avg = data.getStr07_Avg();
                break;
            case 8:
                avg = data.getStr08_Avg();
                break;
            case 9:
                avg = data.getStr09_Avg();
                break;
            case 10:
                avg = data.getStr10_Avg();
                break;
            case 11:
                avg = data.getS01_Avg();
                break;
            case 12:
                avg = data.getS02_Avg();
                break;
            case 13:
                avg = data.getS03_Avg();
                break;
            case 14:
                avg = data.getS04_Avg();
                break;
            case 15:
                avg = data.getS05_Avg();
                break;
            case 16:
                avg = data.getS06_Avg();
                break;
            case 17:
                avg = data.getS07_Avg();
                break;
            case 18:
                avg = data.getS08_Avg();
                break;
            case 19:
                avg = data.getB02_Avg();
                break;
        }
        return avg;
    }

}
